package logic;

import java.util.ArrayList;
import java.util.List;

import persistence.DBCommonAlter;
import jpa_objects.City;
import jpa_objects.Instructor;
import jpa_objects.Instructor_type;
import jpa_objects.Sport;
import json_objects_received.JaxSport;
import json_objects_send.CommonUser;
import json_objects_send.JSON_instructor;

public class CluvieInstructor
{
	public CluvieInstructor()
	{
		super();
	}

	public JSON_instructor registerInstructor(String mail,String name, String birthday,
			String type, String password, String city,String country,String gender, double lat1,
			double lat2, double lat3, double lng1, double lng2, double lng3, List<JaxSport> list) {
		java.sql.Timestamp t=new java.sql.Timestamp(new java.util.Date().getTime());
		try {
			Instructor i=new Instructor("", country,"", ""+t, mail,"",name,0,
					RSA.encryptString(password),"", "",0,"",0, birthday, gender, new Instructor_type(type),
					new City(city, country), lat1, lng1, lat2, lng2, lat3, lng3);
			i.setSports_of_interest(convertJaxSportToSport(list));
			new DBCommonAlter().saveUser(i, DBCommonAlter.SAVE_USER);
			
			return new JSON_instructor(name, convertSports(list), gender, type, false, mail,
					new ArrayList<CommonUser>(), lat1, lng1, lat2, lng2, 
					lat3, lng3);
		} catch (Exception e) {
			
			e.printStackTrace();
			return null;
		}
	}

	private List<Sport> convertJaxSportToSport(List<JaxSport> list) {
		List<Sport> r=new ArrayList<Sport>();
		for (JaxSport s : list) {
			r.add(new Sport(s.getName(),s.getWraper()));
		}
		return r;
	}

	private List<String> convertSports(List<JaxSport> list) {
		List<String> r=new ArrayList<String>();
		for (JaxSport s : list) {
			r.add(s.getName()+"/"+s.getWraper());
		}
		return r;
	}
}
